// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#pragma once

#include <boost/random/uniform_int_distribution.hpp>

#include <pollux/plan/input_generator.h>
#include <pollux/vector/vector_maker.h>

using namespace kumo::pollux::plan;

namespace kumo::pollux::exec::test {

// Generates an integer 1, 2, 3, or 9'000'000'000 as the argument at
// argumentIndex for functions.
class WindowOffsetInputGenerator : public InputGenerator {
 public:
  explicit WindowOffsetInputGenerator(int64_t argumentIndex)
      : argumentIndex_{argumentIndex} {}

  std::vector<VectorPtr> generate(
      const std::vector<TypePtr>& types,
      VectorFuzzer& fuzzer,
      FuzzerGenerator& /*rng*/,
      memory::MemoryPool* pool) override {
    if (types.size() <= argumentIndex_) {
      return {};
    }

    const auto size = fuzzer.getOptions().vectorSize;

    std::vector<VectorPtr> inputs;
    inputs.reserve(argumentIndex_ + 1);
    for (auto i = 0; i < argumentIndex_; ++i) {
      inputs.push_back(fuzzer.fuzz(types[i]));
    }

    kumo::pollux::VectorMaker vectorMaker{pool};
    auto baseN = vectorMaker.flat_vector<int64_t>({1, 2, 3, 9'000'000'000});
    inputs.push_back(fuzzer.fuzzDictionary(baseN, size));

    return inputs;
  }

  void reset() override {}

 private:
  const int64_t argumentIndex_;
};

} // namespace kumo::pollux::exec::test
